const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
// const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = {
  mode: 'development',
  entry: path.resolve(__dirname, 'serve/index.ts'),
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist'),
  },
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'],
        // use: ['extract-tostring-loader', 'extract-loader', 'css-loader', 'postcss-loader', 'sass-loader'],
      },
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 500 * 1024, // <=500kb 则使用 base64 （即，希望字体文件一直使用 base64 ，而不单独打包）
            },
          },
        ],
      },
      {
        test: /\.json5$/i,
        loader: 'json5-loader',
        type: 'javascript/auto',
      },
    ],
  },
  plugins: [new HtmlWebpackPlugin({ template: path.resolve(__dirname, 'serve/index.html') })],
  resolve: {
    extensions: ['.tsx', '.ts', '.js', '.css', '.sass', '.scss', '.json'],
    alias: {
      assets: path.resolve(__dirname, 'src/assets'),
      share: path.resolve(__dirname, 'src/share'),
      editor: path.resolve(__dirname, 'src/editor'),
      menu: path.resolve(__dirname, 'src/menu'),
      content: path.resolve(__dirname, 'src/content'),
      input: path.resolve(__dirname, 'src/input'),
      selection: path.resolve(__dirname, 'src/selection'),
    },
  },
  resolveLoader: {
    modules: ['node_modules', path.resolve(__dirname, 'loaders')],
  },
  devServer: {
    host: '127.0.0.1',
    port: 3692,
    // noInfo: true, // 告诉开发服务器禁止显示诸如 Webpack 捆绑包信息之类的消息
    stats: '',
    overlay: true, // 出现编译器错误或警告时，在浏览器中显示全屏覆盖
    // progress: true, // 将运行进度输出到控制台
    stats: {
      modules: false,
      assets: false,
      children: false,
      colors: true,
    },
  },
}
